'''
Knowtemarks
===========
A simple tool to manage your notes and bookmarks

@author: Markus Fuchs, 2012
'''

import logging, os, sys
from knowtemarks.DataModel import KnowteDao

# configure simple logging output
FORMAT = '%(asctime)-15s <%(name)s> [%(levelname)s] %(message)s'
logging.basicConfig(stream=sys.stdout, format=FORMAT)
log = logging.getLogger("main")
log.setLevel("DEBUG")
    

def getConfFolder():
    """
        get location to store application data. Supported platforms:
        linux. (windows and mac should also work but this is not tested)
        @return: for linux and mac systems ~/.knowtemarks; for windows %APPDATA$\knowtemarks
    """
    f = None
    oname = os.name
    if oname == "nt": # windows
        f = os.path.join(os.getenv("APPDATA"), "knowtemarks")
    elif oname == "posix" or oname == "mac":
        # TODO maybe support XDG_HOME?
        f = os.path.join(os.getenv("HOME"), ".knowtemarks")
    else:
        raise Exception("Unsupported Platform")
    if not os.path.exists(f):
        os.makedirs(f)
    return f

try:
    confFolder = getConfFolder()
    kdao = KnowteDao(os.path.join(confFolder, "knowtes.db"))
    pkgDir = os.path.dirname(os.path.abspath(__file__))
    templateDir = os.path.join(pkgDir, "web", "template")
    staticDir = os.path.join(templateDir, "static")
    port = 8880
except:
    log.exception("Failed to initialize")
    sys.exit(1)
